package com.example.forum_system.forum_systemWebAutoTest.common;

import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.edge.EdgeDriver;
import org.openqa.selenium.edge.EdgeOptions;

import java.time.Duration;
import java.util.concurrent.TimeUnit;

/**
 * @Author: 啵啵虎
 * @Date: 2024-05-27  22:52
 */
public class AutotestUtils {

    public static ChromeDriver chromeDriver;

    public static EdgeDriver edgeDriver;

    //创建驱动对象
    public static ChromeDriver createChromeDriver(){
        //驱动创建好了/没有创建
        if (chromeDriver==null){
            ChromeOptions options=new ChromeOptions();
            options.addArguments("--remote-allow-origins=*");
            chromeDriver=new ChromeDriver(options);
            //隐式等待
            Duration duration=Duration.ofSeconds(10);
            long millis= duration.toMillis();
            chromeDriver.manage().timeouts().implicitlyWait(millis, TimeUnit.MILLISECONDS);
        }
        return chromeDriver;
    }

    public static EdgeDriver createEdgeDriver(){
        //驱动创建好了/没有创建
        if (edgeDriver==null){
            EdgeOptions options=new EdgeOptions();
            options.addArguments("--remote-allow-origins=*");
            edgeDriver=new EdgeDriver(options);
            //隐式等待
            Duration duration=Duration.ofSeconds(10);
            long millis= duration.toMillis();
            edgeDriver.manage().timeouts().implicitlyWait(millis,TimeUnit.MILLISECONDS);
        }
        return edgeDriver;
    }
}
